package com.cms.entity;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.cms.entity.base.BaseRole;
import lombok.EqualsAndHashCode;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Entity - 角色
 * 
 * 
 * 
 */
@SuppressWarnings("serial")
@EqualsAndHashCode(callSuper = false)
@TableName("cms_role")
public class Role extends BaseRole {
	
	
    /**
     * 获取权限
     * 
     * @return 权限
     */
    public List<String> getPermissions() {
        return JSONArray.parseArray(getPermission(), String.class);
    }
	
	/**
	 * 获取站点ID
     *
	 * @return
	 */
	public List<Integer> getSiteIds(){
        List<Object> siteIds = SqlRunner.db().selectObjs("select siteId from cms_role_site where roleId={0} order by id desc",getId());
        return siteIds.stream().map(i->Integer.parseInt(i.toString())).collect(Collectors.toList());
	}

}
